#include "utils.h"
#include "base/threading/thread_restrictions.h"

const wchar_t kMessageWindowClass[] = L"Raster_MessageWindow";

void* SetWindowUserData(HWND hwnd, void* user_data) {
	return
		reinterpret_cast<void*>(SetWindowLongPtr(hwnd, GWLP_USERDATA,
		reinterpret_cast<LONG_PTR>(user_data)));
}

void* GetWindowUserData(HWND hwnd) {
	DWORD process_id = 0;
	DWORD thread_id = GetWindowThreadProcessId(hwnd, &process_id);
	// A window outside the current process needs to be ignored.
	if (process_id != ::GetCurrentProcessId())
		return NULL;
	return reinterpret_cast<void*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
}

bool FileExists(const FilePath& path) {
  base::ThreadRestrictions::AssertIOAllowed();
  DWORD fileattr = ::GetFileAttributes(path.value().c_str());
  if (fileattr != INVALID_FILE_ATTRIBUTES)
    return (fileattr & FILE_ATTRIBUTE_DIRECTORY) == 0;
  return false;
}
